package com.gxa.autoparts.admin.controller;

import com.gxa.autoparts.admin.service.AdviceService;
import com.gxa.autoparts.core.common.JsonResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 廖泓宇
 * 反馈管理
 * @date 2022/1/6 11:31
 */
@RestController
@RequestMapping("/advice")
public class AdviceController {

    @Autowired
    AdviceService adviceService;

//    @PostMapping("/selectAll")
//    @ApiOperation("意见反馈全查询")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
//            @ApiImplicitParam(name = "endTime",value = "结束时间",required = false,dataType = "Date",paramType = "query")
//    })
//    public Map selectAll(){
//        List<Map> maps = adviceService.selectAll();
//        JsonResult jsonResult = new JsonResult();
//        jsonResult.setCode("200");
//        jsonResult.setData(maps);
//        return jsonResult.getDataMap();
//    }

    @PostMapping("/selectByLike")
    @ApiOperation("意见反馈模糊查询和全查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone",value = "手机号",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "name",value = "用户姓名",required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "结束时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "Integer",paramType = "query")
    })
    public Map selectByLike(String phone, String name, String startTime,String endTime,Integer page,Integer size){
        System.out.println("page:"+page);
        System.out.println("size:"+size);
        System.out.println("start:"+startTime);
        System.out.println("end:"+endTime);
        System.out.println("name:"+name);
        List<Map> maps = adviceService.selectByLike(phone, name, startTime, endTime, page, size);
        Integer count = adviceService.count(null, null, null, null, null, null);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        jsonResult.put("count",count);
        return jsonResult.getDataMap();
    }


    @PostMapping("/updateAdvice")
    @ApiOperation("操作反馈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "反馈记录id",required = false,dataType = "Long",paramType = "query"),
            @ApiImplicitParam(name = "remark",value = "处理备注",required = false,dataType = "String",paramType = "query")
    })
    public Map updateAdvice(Long id,String remark){
        adviceService.updateAdvice(id,remark);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }

}
